package Text34;
import java.util.*;
public class Main {
    static int N = 100010;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < n; i++) {
            a[i]=scanner.nextInt();
        }
        Arrays.sort(a,0,n);
        int sum=0;
        for (int i = 0; i < n; i++) {
            sum+=Math.abs(a[i]-a[n/2]);
        }
        System.out.println(sum);
    }
}
